package com.tdam2014.grupo02;

import com.tdam2014.grupo02.Folder;
import com.tdam2014.grupo02.FolderFragment;
import com.tdam2014.grupo02.FolderSelectionListener;
import com.tdam2014.grupo02.MainFragment;
//import com.tdam2014.grupo02.PictureFragment;
import com.tdam2014.grupo02.R;
import com.tdam2014.grupo02.DataBase.DB;

//import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;


public class MainActivity extends ListActivity implements FolderSelectionListener{

	// public final SQLiteDatabase db = DB.GetDB(this);
	public static final String KEY_FOLDER_NAME = "keyName";
	public static final String KEY_FOLDER_ID = "keyID";
	public static final String KEY_LOAD_FOLDER_DATA = "keyLoadPersonData";
	
	private MainFragment mainFragment;
	private FolderFragment folderFragment;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.activity_main);
        mainFragment = (MainFragment) getFragmentManager().findFragmentById(R.id.mainFragment);
        folderFragment = (FolderFragment) getFragmentManager().findFragmentById(R.id.secondaryFragment);
        mainFragment.setFolderSelectionListener(this);
    }
	public void onFolderSelected(Folder folder) {
		if (folderFragment != null) {
			folderFragment.setFolderName(folder.getFolderName());
		} else {
			Intent intent = new Intent(this, FolderActivity.class);
			intent.putExtra(KEY_FOLDER_NAME, folder.getFolderName());
			intent.putExtra(KEY_FOLDER_ID, folder.getFolderId());
			intent.putExtra(KEY_LOAD_FOLDER_DATA, Boolean.TRUE);
			startActivity(intent);
		}

	}
}
